package com.hziee.mail.dao;

import com.hziee.mail.model.ProductClassInfoEntity;
import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @author ZX
 */
public interface ClassifyRepository extends JpaRepository<ProductClassInfoEntity, Integer>, CrudRepository<ProductClassInfoEntity, Integer> {

    /*
     * 获取分类模块中分类大类
     */

    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(nativeQuery = true, value = "SELECT " +
            "*  " +
            "FROM " +
            "product_class_info pci " +
            "WHERE pci.type = 0")
    List<ProductClassInfoEntity> findclassifyLeft();

    /*
     * 获取分类模块中物品初始信息
     */

    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(nativeQuery = true, value = "SELECT " +
            "pci.product_class_id, " +
            "pci.product_class_name, " +
            "pii.p_image_path, " +
            "si.price " +
            "FROM " +
            "product_class_info pci " +
            "JOIN product_image_info pii on pii.product_class_id = pci.product_class_id " +
            "JOIN sku_info si on si.product_class_id = pci.product_class_id " +
            "WHERE " +
            "pci.product_class_id LIKE :productClassId")
    List<Map> findclassifyRight(@Param("productClassId") String productClassId);
}
